package ioc;

import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class IOCRunner extends BlockJUnit4ClassRunner {

	private static Injector testinjector;

	static {
		testinjector = Guice.createInjector(new TestInjector());
	}

	public IOCRunner(Class<?> klass) throws InitializationError {
		super(klass);

	}

	@Override
	protected Object createTest() throws Exception {
		Class<?> javaClass = this.getTestClass().getJavaClass();
		Object newInstance = javaClass.newInstance();
		testinjector.injectMembers(newInstance);
		return newInstance;
	}

}
